package com.ag.zhh.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ag.bean.TbUserDept;
import com.ag.zhh.vo.UserDept;

public class TbUserDeptDAO extends com.ag.dao.TbUserDeptDAO {
	
	public List<TbUserDept> findTbUserDeptByDtId(String dtId) {
		List<TbUserDept> list = null;
		Session session = null;
		
		try {
			session = this.getSessionFactory().openSession();

			System.out.println("**********************************************");
			Query query = session.createQuery("from TbUserDept where tbDeptType.dtId=:dtId and (a=null or a='0') order by GCode");
			query.setString("dtId", dtId);
			list = query.list();
			System.out.println("***************************"+list.size()+"*******");
			
			for(TbUserDept d:list)
			{
				System.out.println(d.getUdId()+"  "+d.getUdName());
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
			
		}
		return list;
	}
	
	public TbUserDept findTbUserDeptJoinTbUser(String id) {
		TbUserDept list = null;
		Session session = null;
		
		try {
			session = this.getSessionFactory().openSession();

			System.out.println("**********************************************");
			Query query = session.createQuery("from TbUserDept ud left join fetch ud.tbUsers where ud.udId=:udId");
			query.setString("udId", id);
			list = (TbUserDept) query.uniqueResult();
			System.out.println("***************************"+list.getUdId()+"*******");
			
			//for(TbUserDept d:list)
			//{
				//System.out.println(d.getUdId()+"  "+d.getUdName());
			//}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
			
		}
		return list;
	}
}
